//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <core.h>
#include <_hal.h>
#include <init.h>
#include "setup.h"

#if defined(_GNUC)

DECL_SECTION(".initpagedir")
    PageDirEntry g_initPageDir[c_uNumberOfPageDirEntries];

DECL_SECTION(".vtpagetab")
    PageTabEntry g_vtPageTable[c_uNumberOfPageTabEntries];

DECL_SECTION(".vtarea")
    byte_t g_vectorTableArea[c_uMaxSizeOfVectorTable];
#elif defined(_EVC)
#pragma data_seg(".initpagedir")
__declspec(allocate(".initpagedir")) \
    PageDirEntry g_initPageDir[c_uNumberOfPageDirEntries];

#pragma data_seg(".vtpagetab")
__declspec(allocate(".vtpagetab")) \
    PageTabEntry g_vtPageTable[c_uNumberOfPageTabEntries];

#pragma data_seg(".vtarea")
__declspec(allocate(".vtarea")) \
    byte_t g_vectorTableArea[c_uMaxSizeOfVectorTable];
#else

#(Unknown the C++ compiler)

#endif

#ifdef _NAKED
#define NUMBEROF_TEMPSECTIONS   4
#else
#define NUMBEROF_TEMPSECTIONS   12
#endif // _NAKED

EXTERN_C DECL_CODEINIT void CDECL SetupPaging(
    physaddr_t paKernelPhysBase, physaddr_t paKernelImagePhysBase,
    physaddr_t paMemoryMappedIoBase, physaddr_t paMemoryMappedIoLimit)
{
    static UInt32 g_kernelPageTable[2];

    memset(g_initPageDir, 0, c_uSizeOfPageDir);
    memset(g_ASIDManage, 0, sizeof(Address) * 256);

    g_kernelPageTable[0] = (UInt32)g_initPageDir;   // It's kernel's ASID
    g_kernelPageTable[1] = 0;

    g_ASIDManage[0] = (UInt32)&g_kernelPageTable;
}

EXTERN DECL_CODEINIT bool_t CDECL InitKernelMapping(
    uint_t uBasePageNo, uint_t uLimitPageNo)
{
    return TRUE;
}
